import time

from selenium import webdriver
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Edge()
driver.get("http://127.0.0.1/ranzhi/www/")
time.sleep(2)
# 用户名密码
driver.find_element("id","account").send_keys("admin")
driver.find_element("id","password").send_keys("123456")
# 点击登录
driver.find_element("id","submit").click()
time.sleep(2)
# 显性等待
locator = ("id","s-menu-1")
input = WebDriverWait(driver,5,0.5).until(expected_conditions.presence_of_element_located(locator))
# 点击客户管理
driver.find_element("id","s-menu-1").click()
# 切换到iframe
locator = ("id","iframe-1")
input = WebDriverWait(driver,5,0.5).until(expected_conditions.presence_of_element_located(locator))
# 定位到iframe
iframe = driver.find_element("id","iframe-1")
driver.switch_to.frame(iframe)
# 显性等待
locator1 = ("xpath",'//*[@id="mainNavbar"]/ul/li[4]/a')
input1 = WebDriverWait(driver,5,0.5).until(expected_conditions.presence_of_element_located(locator1))
# 点击客户
driver.find_element("xpath",'//*[@id="mainNavbar"]/ul/li[4]/a').click()
time.sleep(3)
# 显性等待
locator2 = ("class name","btn.btn-primary")
input2 = WebDriverWait(driver,5,0.5).until(expected_conditions.presence_of_element_located(locator2))
# 点击添加客户
driver.find_element("class name","icon-plus").click()
time.sleep(2)
# 名称
driver.find_element("name","name").send_keys("王总")
time.sleep(2)
# 联系人
driver.find_element("name","contact").send_keys("王文浩")
time.sleep(2)
# 电话
driver.find_element("name","phone").send_keys("18434795728")
time.sleep(2)
#邮箱
driver.find_element("name","email").send_keys("2459496851@qq.com")
time.sleep(2)
# QQ
driver.find_element("name","qq").send_keys("2459496851")
time.sleep(2)
# 对公账户
driver.find_element("name","depositor").send_keys("1234567890")
time.sleep(2)
# 类型
lx = driver.find_element("id","type")
    # 强转为select对象
x = Select(lx)
    # 获取所有的下拉选项的对象
ls = x.options
lstext = []
for i in ls:
    lstext.append(i.text)
    # 选中
x.select_by_visible_text(lstext[1])
time.sleep(2)
# 规模
gm = driver.find_element("name","size")
    # 强转为select对象
m = Select(gm)
    # 获取所有的下拉选项的对象
ls1 = m.options
lstext1 = []
for j in ls1:
    lstext1.append(j.text)
    # 选中
m.select_by_visible_text(lstext1[1])
time.sleep(2)
# 状态
zt = driver.find_element("name","status")
    # 强转为select对象
t = Select(zt)
    # 获取所有的下拉选项的对象
ls2 = t.options
lstext2 = []
for n in ls2:
    lstext2.append(n.text)
    # 选中
t.select_by_visible_text(lstext2[1])
time.sleep(2)
# 级别
jb = driver.find_element("id","level")
    # 强转为select对象
b = Select(jb)
    # 获取所有的下拉选项的对象
ls3 = b.options
lstext3 = []
for k in ls3:
    lstext3.append(k.text)
    # 选中
b.select_by_visible_text(lstext3[1])
time.sleep(2)
# 地址
driver.find_element("name","address[title]").send_keys("中国")
driver.find_element("name","address[location]").send_keys("西安")
time.sleep(2)
# 购买意向
driver.find_element("name","intension").send_keys("无")
time.sleep(2)
# 保存
driver.find_element("id","submit").click()
time.sleep(3)
